package com.zhaotianhao.check.comboserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhaotianhao.check.comboserver.entity.Combo;
import com.zhaotianhao.check.comboserver.entity.ComboVO;
import com.zhaotianhao.check.comboserver.mapper.ComboMapper;
import com.zhaotianhao.check.comboserver.service.IComboService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.function.Consumer;

/**
 * <p>
 * 套餐表 服务实现类
 * </p>
 *
 * @author Z-7
 * @since 2022-03-29
 */
@Service
public class ComboServiceImpl extends ServiceImpl<ComboMapper, Combo> implements IComboService {

    /**
     * 列表
     *
     * @param comboVO
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<Combo> getPageInfo(ComboVO comboVO, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        if(!StringUtils.hasText(comboVO.getCondition())){
            return new PageInfo<>(list());
        }

        QueryWrapper<Combo> queryWrapper = new QueryWrapper<Combo>();
        queryWrapper.eq("combo_coding",comboVO.getCondition())
                .or().likeRight("combo_name",comboVO.getCondition())
                .or().eq("combo_code",comboVO.getCondition());
        List<Combo> list = getBaseMapper().selectList(queryWrapper);
        return new PageInfo<>(list);
    }
}
